package com.tskj.leonsu.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tskj.leonsu.service.LoginService;
import com.tskj.leonsu.service.RestaurantService;
import com.tskj.leonsu.utility.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/food")
public class MobileController {

    @Autowired
    private RestaurantService restaurantService;

    @Autowired
    private LoginService loginService;

    /**
     * 获取餐厅列表
     * @return
     */
    @GetMapping("/restaurant")
    @ResponseBody
    public JSONObject getRestaurant() {
        JSONObject ret = new JSONObject();
        JSONArray list = restaurantService.getRestaurant();
        ret.put("code", 0);
        ret.put("data", list);
        return ret;
    }

    @GetMapping("/check")
    @ResponseBody
    public JSONObject getCanteenStatus() {
        JSONObject ret = new JSONObject();
        ret.put("code", 0);
        ret.put("data", restaurantService.getCanteenStatus());
        return ret;
    }
    /**
     * 获取分餐时间段，早餐、中餐、晚餐
     * @return
     */
    @GetMapping("/type")
    @ResponseBody
    public JSONObject getTimeType() {
        JSONObject ret = new JSONObject();
        JSONArray list = restaurantService.getTimeType();
        ret.put("code", 0);
        ret.put("data", list);
        return ret;
    }

    /**
     * 获取餐厅下的套餐列表
     * @return
     */
    @GetMapping("/foodList")
    @ResponseBody
    public JSONObject getFoodList(@RequestParam String restaurantId, @RequestParam String timeTypeId) {
        JSONObject ret = new JSONObject();
        JSONArray list = restaurantService.getFoodList(restaurantId, timeTypeId);
        ret.put("code", 0);
        ret.put("data", list);
        return ret;
    }

    @GetMapping("/checkStopTime")
    @ResponseBody
    public JSONObject checkStopTime(@RequestParam String token, @RequestParam String resId, @RequestParam String timeTypeId) {
        String adUserName = loginService.getAdUserName(token);
        JSONObject ret = new JSONObject();
        ret.put("code", 0);
        ret.put("data", restaurantService.checkOrder(adUserName, Tools.today(), resId, timeTypeId));
        return ret;
    }
}
